{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Import standard libraries for numerics and plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Import the package MultiNetX"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import multinetx as mx"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Create three Erd\"os- R'enyi networks with N nodes for each layer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "N = 8\n",
    "g1 = mx.generators.erdos_renyi_graph(N,0.9,seed=218)\n",
    "g2 = mx.generators.erdos_renyi_graph(N,0.9,seed=211)\n",
    "g3 = mx.generators.erdos_renyi_graph(N,0.9,seed=208)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Create an 3Nx3N lil sparse matrix. It will be used to describe the layers interconnection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "adj_block = mx.lil_matrix(np.zeros((N*3,N*3)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Define the type of interconnection among the layers (here we use identity matrices thus connecting one-to-one the nodes among layers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "adj_block[0:  N,  N:2*N] = np.identity(N)    # L_12\n",
    "adj_block[0:  N,2*N:3*N] = np.identity(N)    # L_13\n",
    "adj_block[N:2*N,2*N:3*N] = np.identity(N)    # L_23\n",
    "\n",
    "# use symmetric inter-adjacency matrix\n",
    "adj_block += adj_block.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Create an instance of the MultilayerGraph class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "mg = mx.MultilayerGraph(list_of_layers=[g1,g2,g3],\n",
    "                        inter_adjacency_matrix=adj_block)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Weights can be added to the edges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "mg.set_edges_weights(intra_layer_edges_weight=2,\n",
    "                     inter_layer_edges_weight=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Take some information for the multiplex network"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MultiNetX name:\n",
      " multilayer___ \n",
      " 3-layer graph,                intra_layer_edges:100,                inter_layer_edges:24,                number_of_nodes_in_layer:[8, 8, 8]  \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print ('MultiNetX name:\\n', mg.name ,'\\n', mg.info(),'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MultilayerGraph edges: \n",
      "\n",
      " intra-layer edges:  [(0, 1), (0, 2), (0, 4), (0, 5), (0, 7), (0, 8), (0, 16), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 9), (1, 17), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 10), (2, 18), (3, 4), (3, 5), (3, 6), (3, 7), (3, 11), (3, 19), (4, 5), (4, 6), (4, 7), (4, 12), (4, 20), (5, 7), (5, 13), (5, 21), (6, 7), (6, 14), (6, 22), (7, 15), (7, 23), (8, 9), (8, 10), (8, 11), (8, 12), (8, 13), (8, 14), (8, 15), (8, 16), (9, 10), (9, 11), (9, 12), (9, 13), (9, 14), (9, 15), (9, 17), (10, 11), (10, 12), (10, 13), (10, 14), (10, 18), (11, 12), (11, 13), (11, 14), (11, 15), (11, 19), (12, 14), (12, 15), (12, 20), (13, 15), (13, 21), (14, 15), (14, 22), (15, 23), (16, 17), (16, 18), (16, 19), (16, 20), (16, 21), (16, 22), (16, 23), (17, 18), (17, 19), (17, 21), (17, 22), (17, 23), (18, 20), (18, 21), (18, 22), (18, 23), (19, 20), (19, 21), (19, 22), (19, 23), (20, 21), (20, 22), (20, 23), (21, 22), (21, 23), (22, 23)] \n",
      "\n",
      " inter-layer edges:  [(8, 0), (9, 1), (10, 2), (11, 3), (12, 4), (13, 5), (14, 6), (15, 7), (16, 0), (16, 8), (17, 1), (17, 9), (18, 2), (18, 10), (19, 3), (19, 11), (20, 4), (20, 12), (21, 5), (21, 13), (22, 6), (22, 14), (23, 7), (23, 15)] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print ('MultilayerGraph edges:',\\\n",
    "        '\\n\\n intra-layer edges: ',mg.get_intra_layer_edges(),\\\n",
    "        '\\n\\n inter-layer edges: ',mg.get_inter_layer_edges(),'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "intralayer edges of 1:  [(0, 1), (0, 2), (0, 4), (0, 5), (0, 7), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (3, 4), (3, 5), (3, 6), (3, 7), (4, 5), (4, 6), (4, 7), (5, 7), (6, 7)]\n",
      "intralayer edges of 2:  [(8, 9), (8, 10), (8, 11), (8, 12), (8, 13), (8, 14), (8, 15), (9, 10), (9, 11), (9, 12), (9, 13), (9, 14), (9, 15), (10, 11), (10, 12), (10, 13), (10, 14), (11, 12), (11, 13), (11, 14), (11, 15), (12, 14), (12, 15), (13, 15), (14, 15)]\n",
      "intralayer edges of 3:  [(16, 17), (16, 18), (16, 19), (16, 20), (16, 21), (16, 22), (16, 23), (17, 18), (17, 19), (17, 21), (17, 22), (17, 23), (18, 20), (18, 21), (18, 22), (18, 23), (19, 20), (19, 21), (19, 22), (19, 23), (20, 21), (20, 22), (20, 23), (21, 22), (21, 23), (22, 23)]\n"
     ]
    }
   ],
   "source": [
    "print ('intralayer edges of 1: ',mg.get_intra_layer_edges_of_layer(layer=0))\n",
    "print ('intralayer edges of 2: ',mg.get_intra_layer_edges_of_layer(layer=1))\n",
    "print ('intralayer edges of 3: ',mg.get_intra_layer_edges_of_layer(layer=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### A layer can be chosen: it is a networkx.Graph so it inherits all of its properties."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "layer 1  name is \n"
     ]
    }
   ],
   "source": [
    "layer = 1\n",
    "mg1 = mg.get_layer(layer-1)\n",
    "print ('layer', layer, ' name is', mg1.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adjacency matrix:\n",
      " [[0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]\n",
      " [1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0]\n",
      " [1 1 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0]\n",
      " [0 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0]\n",
      " [1 1 1 1 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0]\n",
      " [1 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0]\n",
      " [0 1 1 1 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0]\n",
      " [1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1]\n",
      " [1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0]\n",
      " [0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0]\n",
      " [0 0 1 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 0]\n",
      " [0 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0]\n",
      " [0 0 0 0 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 0 0]\n",
      " [0 0 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 0 0 0 0 1 0 0]\n",
      " [0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 1 0 0 0 0 0 0 1 0]\n",
      " [0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 0 1]\n",
      " [1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1]\n",
      " [0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1]\n",
      " [0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 1]\n",
      " [0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 1 1]\n",
      " [0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 1 1 1]\n",
      " [0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 1 1]\n",
      " [0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1]\n",
      " [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0]] \n",
      "\n",
      "Adjacency matrix (weighted):\n",
      " [[0 2 2 0 2 2 0 2 3 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0]\n",
      " [2 0 2 2 2 2 2 2 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0 0]\n",
      " [2 2 0 2 2 2 2 2 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0]\n",
      " [0 2 2 0 2 2 2 2 0 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0]\n",
      " [2 2 2 2 0 2 2 2 0 0 0 0 3 0 0 0 0 0 0 0 3 0 0 0]\n",
      " [2 2 2 2 2 0 0 2 0 0 0 0 0 3 0 0 0 0 0 0 0 3 0 0]\n",
      " [0 2 2 2 2 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 0 0 3 0]\n",
      " [2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 3]\n",
      " [3 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 3 0 0 0 0 0 0 0]\n",
      " [0 3 0 0 0 0 0 0 2 0 2 2 2 2 2 2 0 3 0 0 0 0 0 0]\n",
      " [0 0 3 0 0 0 0 0 2 2 0 2 2 2 2 0 0 0 3 0 0 0 0 0]\n",
      " [0 0 0 3 0 0 0 0 2 2 2 0 2 2 2 2 0 0 0 3 0 0 0 0]\n",
      " [0 0 0 0 3 0 0 0 2 2 2 2 0 0 2 2 0 0 0 0 3 0 0 0]\n",
      " [0 0 0 0 0 3 0 0 2 2 2 2 0 0 0 2 0 0 0 0 0 3 0 0]\n",
      " [0 0 0 0 0 0 3 0 2 2 2 2 2 0 0 2 0 0 0 0 0 0 3 0]\n",
      " [0 0 0 0 0 0 0 3 2 2 0 2 2 2 2 0 0 0 0 0 0 0 0 3]\n",
      " [3 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2]\n",
      " [0 3 0 0 0 0 0 0 0 3 0 0 0 0 0 0 2 0 2 2 0 2 2 2]\n",
      " [0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0 2 2 0 0 2 2 2 2]\n",
      " [0 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 2 2 0 0 2 2 2 2]\n",
      " [0 0 0 0 3 0 0 0 0 0 0 0 3 0 0 0 2 0 2 2 0 2 2 2]\n",
      " [0 0 0 0 0 3 0 0 0 0 0 0 0 3 0 0 2 2 2 2 2 0 2 2]\n",
      " [0 0 0 0 0 0 3 0 0 0 0 0 0 0 3 0 2 2 2 2 2 2 0 2]\n",
      " [0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 3 2 2 2 2 2 2 2 0]] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print ('Adjacency matrix:\\n', \\\n",
    "        mx.adjacency_matrix(mg,weight=None).todense(),'\\n')\n",
    "print ('Adjacency matrix (weighted):\\n', \\\n",
    "        mx.adjacency_matrix(mg,weight=\"weight\").todense(),'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAALlklEQVR4nO3dT6hc9RnG8edptBt1EcltCDFtrIRCNo29QxAqRbGV6Ca6EV2ULIS4UFBwE9zopuBG7UaEiCFZ+AdBrVmE1hCEtFDEiQSNppIgKRquuTe40J1E3y7uCdzGO3dOZn5zzpl5vx8YZubM3Hve+d15+J2Z895zHBECMPt+1nYBAJpB2IEkCDuQBGEHkiDsQBLXNLmyDRs2xNatW9d8zokTJ4qsa35+fuhzmlxXG+ubRXXGMPP4nDt3ThcvXvRqj7nJXW+9Xi/6/f6az7FXrfOq1XldTa6rjfXNojpjmHl8er2e+v3+qoM01ma87V22P7d91va+cX4XgMkaOey210l6UdI9krZLesj29lKFAShrnJl9p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JOkWSTskLUh6rt1yVmf7eklvSXoiIr5d+ViXxrqtsJ+XtGXF/ZuqZZ0WEeer60VJ72j548i0uGB7kyRV14st1zNURFyIiB8i4kdJL6uD4237Wi0H/dWIeLta3MmxbivsH0raZvtm2z+X9KCkwy3VUovt62zfcPm2pLslnVr7pzrlsKQ91e09kt5tsZZaLgemcr86Nt5ePvbzK5JOR8TzKx7q5Fi31kFX7Ub5q6R1kg5ExF9aKaQm27/W8mwuLR9v/7Wu1mz7dUl3aPlfLS9IelrS3yS9KemXWv434wciojNfiA2o+Q4tb8KHpHOSHlnxWbh1tm+X9E9Jn0j6sVr8lJY/t3durGmXBZLgCzogCcIOJEHYgSQIO5AEYQeSIOxAEoQdSOJ/SWJpMJGKFaoAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "ax.imshow(mx.adjacency_matrix(mg,weight=None).todense(),\n",
    "          origin='upper',interpolation='nearest',cmap=plt.cm.binary);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Laplacian matrix:\n",
      " [[ 7 -1 -1  0 -1 -1  0 -1 -1  0  0  0  0  0  0  0 -1  0  0  0  0  0  0  0]\n",
      " [-1  9 -1 -1 -1 -1 -1 -1  0 -1  0  0  0  0  0  0  0 -1  0  0  0  0  0  0]\n",
      " [-1 -1  9 -1 -1 -1 -1 -1  0  0 -1  0  0  0  0  0  0  0 -1  0  0  0  0  0]\n",
      " [ 0 -1 -1  8 -1 -1 -1 -1  0  0  0 -1  0  0  0  0  0  0  0 -1  0  0  0  0]\n",
      " [-1 -1 -1 -1  9 -1 -1 -1  0  0  0  0 -1  0  0  0  0  0  0  0 -1  0  0  0]\n",
      " [-1 -1 -1 -1 -1  8  0 -1  0  0  0  0  0 -1  0  0  0  0  0  0  0 -1  0  0]\n",
      " [ 0 -1 -1 -1 -1  0  7 -1  0  0  0  0  0  0 -1  0  0  0  0  0  0  0 -1  0]\n",
      " [-1 -1 -1 -1 -1 -1 -1  9  0  0  0  0  0  0  0 -1  0  0  0  0  0  0  0 -1]\n",
      " [-1  0  0  0  0  0  0  0  9 -1 -1 -1 -1 -1 -1 -1 -1  0  0  0  0  0  0  0]\n",
      " [ 0 -1  0  0  0  0  0  0 -1  9 -1 -1 -1 -1 -1 -1  0 -1  0  0  0  0  0  0]\n",
      " [ 0  0 -1  0  0  0  0  0 -1 -1  8 -1 -1 -1 -1  0  0  0 -1  0  0  0  0  0]\n",
      " [ 0  0  0 -1  0  0  0  0 -1 -1 -1  9 -1 -1 -1 -1  0  0  0 -1  0  0  0  0]\n",
      " [ 0  0  0  0 -1  0  0  0 -1 -1 -1 -1  8  0 -1 -1  0  0  0  0 -1  0  0  0]\n",
      " [ 0  0  0  0  0 -1  0  0 -1 -1 -1 -1  0  7  0 -1  0  0  0  0  0 -1  0  0]\n",
      " [ 0  0  0  0  0  0 -1  0 -1 -1 -1 -1 -1  0  8 -1  0  0  0  0  0  0 -1  0]\n",
      " [ 0  0  0  0  0  0  0 -1 -1 -1  0 -1 -1 -1 -1  8  0  0  0  0  0  0  0 -1]\n",
      " [-1  0  0  0  0  0  0  0 -1  0  0  0  0  0  0  0  9 -1 -1 -1 -1 -1 -1 -1]\n",
      " [ 0 -1  0  0  0  0  0  0  0 -1  0  0  0  0  0  0 -1  8 -1 -1  0 -1 -1 -1]\n",
      " [ 0  0 -1  0  0  0  0  0  0  0 -1  0  0  0  0  0 -1 -1  8  0 -1 -1 -1 -1]\n",
      " [ 0  0  0 -1  0  0  0  0  0  0  0 -1  0  0  0  0 -1 -1  0  8 -1 -1 -1 -1]\n",
      " [ 0  0  0  0 -1  0  0  0  0  0  0  0 -1  0  0  0 -1  0 -1 -1  8 -1 -1 -1]\n",
      " [ 0  0  0  0  0 -1  0  0  0  0  0  0  0 -1  0  0 -1 -1 -1 -1 -1  9 -1 -1]\n",
      " [ 0  0  0  0  0  0 -1  0  0  0  0  0  0  0 -1  0 -1 -1 -1 -1 -1 -1  9 -1]\n",
      " [ 0  0  0  0  0  0  0 -1  0  0  0  0  0  0  0 -1 -1 -1 -1 -1 -1 -1 -1  9]] \n",
      "\n",
      "Laplacian matrix (weighted):\n",
      " [[16 -2 -2  0 -2 -2  0 -2 -3  0  0  0  0  0  0  0 -3  0  0  0  0  0  0  0]\n",
      " [-2 20 -2 -2 -2 -2 -2 -2  0 -3  0  0  0  0  0  0  0 -3  0  0  0  0  0  0]\n",
      " [-2 -2 20 -2 -2 -2 -2 -2  0  0 -3  0  0  0  0  0  0  0 -3  0  0  0  0  0]\n",
      " [ 0 -2 -2 18 -2 -2 -2 -2  0  0  0 -3  0  0  0  0  0  0  0 -3  0  0  0  0]\n",
      " [-2 -2 -2 -2 20 -2 -2 -2  0  0  0  0 -3  0  0  0  0  0  0  0 -3  0  0  0]\n",
      " [-2 -2 -2 -2 -2 18  0 -2  0  0  0  0  0 -3  0  0  0  0  0  0  0 -3  0  0]\n",
      " [ 0 -2 -2 -2 -2  0 16 -2  0  0  0  0  0  0 -3  0  0  0  0  0  0  0 -3  0]\n",
      " [-2 -2 -2 -2 -2 -2 -2 20  0  0  0  0  0  0  0 -3  0  0  0  0  0  0  0 -3]\n",
      " [-3  0  0  0  0  0  0  0 20 -2 -2 -2 -2 -2 -2 -2 -3  0  0  0  0  0  0  0]\n",
      " [ 0 -3  0  0  0  0  0  0 -2 20 -2 -2 -2 -2 -2 -2  0 -3  0  0  0  0  0  0]\n",
      " [ 0  0 -3  0  0  0  0  0 -2 -2 18 -2 -2 -2 -2  0  0  0 -3  0  0  0  0  0]\n",
      " [ 0  0  0 -3  0  0  0  0 -2 -2 -2 20 -2 -2 -2 -2  0  0  0 -3  0  0  0  0]\n",
      " [ 0  0  0  0 -3  0  0  0 -2 -2 -2 -2 18  0 -2 -2  0  0  0  0 -3  0  0  0]\n",
      " [ 0  0  0  0  0 -3  0  0 -2 -2 -2 -2  0 16  0 -2  0  0  0  0  0 -3  0  0]\n",
      " [ 0  0  0  0  0  0 -3  0 -2 -2 -2 -2 -2  0 18 -2  0  0  0  0  0  0 -3  0]\n",
      " [ 0  0  0  0  0  0  0 -3 -2 -2  0 -2 -2 -2 -2 18  0  0  0  0  0  0  0 -3]\n",
      " [-3  0  0  0  0  0  0  0 -3  0  0  0  0  0  0  0 20 -2 -2 -2 -2 -2 -2 -2]\n",
      " [ 0 -3  0  0  0  0  0  0  0 -3  0  0  0  0  0  0 -2 18 -2 -2  0 -2 -2 -2]\n",
      " [ 0  0 -3  0  0  0  0  0  0  0 -3  0  0  0  0  0 -2 -2 18  0 -2 -2 -2 -2]\n",
      " [ 0  0  0 -3  0  0  0  0  0  0  0 -3  0  0  0  0 -2 -2  0 18 -2 -2 -2 -2]\n",
      " [ 0  0  0  0 -3  0  0  0  0  0  0  0 -3  0  0  0 -2  0 -2 -2 18 -2 -2 -2]\n",
      " [ 0  0  0  0  0 -3  0  0  0  0  0  0  0 -3  0  0 -2 -2 -2 -2 -2 20 -2 -2]\n",
      " [ 0  0  0  0  0  0 -3  0  0  0  0  0  0  0 -3  0 -2 -2 -2 -2 -2 -2 20 -2]\n",
      " [ 0  0  0  0  0  0  0 -3  0  0  0  0  0  0  0 -3 -2 -2 -2 -2 -2 -2 -2 20]] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print ('Laplacian matrix:\\n',mx.laplacian_matrix(mg,weight=None).todense(),'\\n')\n",
    "print ('Laplacian matrix (weighted):\\n', mx.laplacian_matrix(mg,weight=\"weight\").todense(),'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACx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288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111)\n",
    "ax.imshow(mx.laplacian_matrix(mg,weight=None).todense(),\n",
    "          origin='upper',interpolation='nearest',cmap=plt.cm.binary);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Laplacian spectrum:\n",
      " [2.82374242e-15 9.00000000e+00 9.00000000e+00 1.15820412e+01\n",
      " 1.30000000e+01 1.36118630e+01 1.40468718e+01 1.48269378e+01\n",
      " 1.53667455e+01 1.58555302e+01 1.99399232e+01 2.15325431e+01\n",
      " 2.21475930e+01 2.25804624e+01 2.32964508e+01 2.36688531e+01\n",
      " 2.41420291e+01 2.44021557e+01 2.50000000e+01 2.50000000e+01\n",
      " 2.50000000e+01 2.50000000e+01 2.50000000e+01 2.50000000e+01] \n",
      "\n"
     ]
    }
   ],
   "source": [
    "print ('Laplacian spectrum:\\n', \\\n",
    "        mx.laplacian_spectrum(mg,weight=\"weight\"),'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
